/**
 * @Author: zxc
 * @Date: 2020-11-04 13:18:16
 * @func:Z字形变换
 */

/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function (s, numRows) {
  const len = s.length
  if (numRows === 1 || len <= numRows) return s
  const rows = new Array(len).fill("")
  let idx = 0,
    hasDown = false
  for (let i of s) {
    rows[idx] = rows[idx] + i
    if (idx === 0 || idx === numRows - 1) hasDown = !hasDown
    idx = hasDown ? idx + 1 : idx - 1
  }
  return rows.join("")
}
